#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=freetype
version=2.10.4

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	tar -xf $SRC/$name-doc-$version.tar.xz --strip-components=2 -C docs

	sed -ri "s:.*(AUX_MODULES.*valid):\1:" modules.cfg

	sed -r "s:.*(#.*SUBPIXEL_RENDERING) .*:\1:" \
	    -i include/freetype/config/ftoption.h

	./configure --prefix=/usr --enable-freetype-config --disable-static
	make

	make install

	install -v -m755 -d /usr/share/doc/$name-$version
	cp -v -R docs/*     /usr/share/doc/$name-$version
	rm -v /usr/share/doc/$name-$version/freetype-config.1

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
